local dir `c(pwd)'
local g=`1'
qui {
clear
set obs 1
foreach type in original order structure {
gen H_`type'=.
}
gen i=.
gen book=.             
gen str translation=""	                        
save  entropy_bible_`g', replace

use calculation_`g', clear

local till=_N
local counter=_N

forvalues i=1/`till' {
	use calculation_`g', clear
	local translation=translation[`i']
	local counter=`counter'-1
	
	noisily di "`translation' (left: `counter') "
    	
	foreach book in 100		{			
		foreach type in original order structure {
		import delimited `"`dir'\\shortestmismatches_validation_VI\\`translation'_`book'_`type'.txt.sm.txt"', delimiter(tab) varnames(nonames) stripquote(no) bindquotes(nobind) case(preserve) encoding(UTF-8) clear   
		gen i=_n
		gen li=v2
		gen H_`type'=	(li)/(log(i+1)/log(2))
		replace H_`type'=(sum(H_`type')/i)^(-1)
		/*keep every 1,000th observation */
		keep if (mod(_n,1000))==0
		keep i H_`type'
		save H_`type'_`g', replace			
		}
		use H_original_`g', clear
		merge 1:1 i using H_order_`g', nogenerate
		merge 1:1 i using H_structure_`g', nogenerate
		foreach type in original order structure {
			capture erase  H_`type'_`g'.dta
		}
		gen translation="`translation'"
		gen book=`book'                     			
		append using  entropy_bible_`g' 
		save  entropy_bible_`g', replace
				}
			}
/* generate finished file */
clear
set obs 1
gen v=1
save finished_`g', replace
}

clear         
exit, STATA 	
